local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();
local LanguageHelper= _G.LanguageHelper
local Asset_Cfg=ClientOHOH.config.Asset
function InitInsts(ui)
	ui.insts = {
        cell1 = {
            icon = "ctrl.cell1.icon",
            name = "ctrl.cell1.name",
            val = "ctrl.cell1.val"
        },
        cell2 = {
            root = "ctrl.cell2.root",
            icon = "ctrl.cell2.icon",
            name = "ctrl.cell2.name",
            val = "ctrl.cell2.val"
        },
        name = "ctrl.name",
        probability = "ctrl.probability",
        root = "ctrl.root",
        total = "ctrl.total"
    };
end;

function M.new(...)
	return M(...);
end;

function M.ctor(self)
    InitInsts(self)
    M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.PartInfoPop"));
    self.main_inst.Enabled=false
end;

function M.dtor(self)
	M.super.dtor(self);
end;

function M.OnShow(self,cell) --显示Cell信息
    self.main_inst.Enabled=true
    local cfg = cell:GetPartCfgData()
    self.insts.name.Text=LanguageHelper:GetText(cfg.name) 
    self.insts.probability.Text="1 in "..cfg.weight
    -- self.insts.total.Text=""

    --cell1,cell2
    for index, value in pairs(cfg.value) do
        if index==1 then
            self.insts.cell2.root.Visible = false
        else
            self.insts.cell2.root.Visible = true
        end
        -- local iconName = "car_part_use_"..cfg.property[index]
        -- for _, value in pairs(Asset_Cfg) do
        --     if value.name == iconName then
        --         self.insts["cell"..index].icon.Image = value.rid
        --     end
       local emojiTxt = LanguageHelper:GetText(5551000+cfg.property[index]) 
        self.insts["cell"..index].icon.Text = emojiTxt

        self.insts["cell"..index].name.Text = LanguageHelper:GetText(9991000+cfg.property[index]) 
        if cfg.valueType == 1 then
            self.insts["cell"..index].val.Text = BigNumberHelper:ToString(value)
        else
            self.insts["cell"..index].val.Text = BigNumberHelper:ToString(value*100).."%" 
        end
    end

    local pos = cell:GetAbsolutePosition()
    self.insts.root.Position=UDim2.fromOffset(pos.X+10,pos.Y)
end

function M.OnHide(self)
    self.main_inst.Enabled=false
end



return M